package main

import (
	"fmt"

	"bufio"
	"os"
	"unsafe"

	"strings"

	"./weixin"
)

func main() {
	wx, err := weixin.NewWeiXin()
	if err != nil {
		panic(err)
	}
	fmt.Println("you can input:")

	to := ""
	bio := bufio.NewReader(os.Stdin)
	for {
		line, _, err := bio.ReadLine()
		if err != nil {
			panic(err)
		}
		lineStr := *(*string)(unsafe.Pointer(&line))

		if strings.HasPrefix(lineStr, "to:") {
			to = string(line[3:])
		} else if to != "" && strings.TrimSpace(lineStr) != "" {
			if err = wx.SendMsg(to, lineStr); err != nil {
				fmt.Printf("SendMsg :%s\n", err)
			}
		}
	}
}
